import { DELETE, GET, Params, POST, PUT, Result } from '@/plugins/axios';
import type { ResponseResult } from '@/types/response';
import type { CategoryApiType } from './namespace';
import { handleResponseMessage } from '@/utils/common';

class CategoryApi {
  @GET('category')
  async list(
    @Params data?: CategoryApiType.CategoryRequest,
    @Result res?: ResponseResult<CategoryApiType.Category[]>,
  ): Promise<CategoryApiType.Category[]> {
    return res?.data ?? [];
  }

  @POST('category')
  async create(@Params data: CategoryApiType.CategoryRequest, @Result res?: ResponseResult<CategoryApiType.Category>) {
    handleResponseMessage(res);
  }

  @DELETE('category')
  async delete(@Params data: { id: string }, @Result res?: ResponseResult<CategoryApiType.Category>) {
    handleResponseMessage(res);
  }

  @PUT('category')
  async put(@Params data: CategoryApiType.Category, @Result res?: ResponseResult<CategoryApiType.Category>) {
    handleResponseMessage(res);
  }
}

export default new CategoryApi();
